new Vue({
    el: '#app',
    mixins: [Query],//组件配置文件，路径/utils/components.js
    data() {
        return {
            form: {//查询筛选
                value: '',
                value2: '-',
                value3: '',
                value4: '',
                PageNumber: 1, //页码
                RowAmount: 20,
                Condition: utf8ToBase64("%%,%%,%%,%%"),
            },
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.getColumn(); //查询表头数据
         * 2.this.getList(this.form); //查询表格数据
         * 3.this.getTreeData();//查询树
         */
    },
    methods: {
        handleSerach() { //筛选
            this.form.Condition = utf8ToBase64(`%${this.form.value}%,%${(this.form.value2 != '-' ? this.form.value2 : '')}%,${this.form.value3}%,%${this.form.value4}%`);
            this.getList(this.form);
        },
        getTreeData() {
            $.ajax({
                url: absolutepath() + 'admin/data/dtree.json',
                type: 'GET',
                success: (data) => {
                    this.treeData = data;
                },
            })
        },
        handleNodeClick(data, node) {//筛选树
            if (node.level == 1) {//省
                this.form.value3 = data.code.substring(0, 2);
            } else if (node.level == 2) {//市
                this.form.value3 = data.code.substring(0, 4);
            } else if (node.level == 3) {//区
                this.form.value3 = data.code;
            }
            this.form.Condition = utf8ToBase64(`%${this.form.value}%,%${(this.form.value2 != '-' ? this.form.value2 : '')}%,${this.form.value3}%,%${this.form.value4}%`);
            this.getList(this.form);
        },
        handleStatus(row) { //禁用 or 启用
            this.$confirm(`此操作将${row.Row_Status == '0' ? '启用' : '禁用'}该数据, 是否继续?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                try {
                    const { tableName, primaryKey } = $('#table').data('options');
                    httpRequest({
                        url: '/generalBusiness/generalQueryByTableNameWithOriginal',
                        data: {
                            Data: tableName,
                            Condition: `${primaryKey}='${row[primaryKey]}'`
                        }
                    }).then(data => {
                        if (data.length == 1) {
                            data[0].Row_Status = (row.Row_Status == '0' ? '2' : '0');
                            let lJSONObject_Modify = new Object();
                            lJSONObject_Modify[tableName] = data;
                            //组合
                            let lJSONObject_DataSet = {
                                Modify: lJSONObject_Modify, Add: {}
                            };
                            let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                            lJSONObject_DataSet['Add']['base_operation_log'] = [{
                                Operation_Type: '0',
                                Operation_Path: getRelativePath(),
                                Operation_Description: (row.Row_Status == '0' ? '启用' : '禁用') + '商户数据',
                                Operation_Main,
                                Operation_Interface: "generalSaveByRequestBody",
                                Operation_IP: getIpAddress()
                            }]
                            httpRequest({
                                contentType: 'JSON',
                                url: '/generalBusiness/generalSaveByRequestBody',
                                data: JSON.stringify({
                                    Data: lJSONObject_DataSet
                                })
                            }).then(res => {
                                if (res.Status == "success") {
                                    this.getList(this.form);
                                    this.$message.success((row.Row_Status == '0' ? '启用' : '禁用') + "成功");
                                } else {
                                    this.$message.error((row.Row_Status == '0' ? '启用' : '禁用') + "失败，请重试！");
                                }
                            }).catch(xhr => {
                                this.$message({
                                    message: '系统错误，请联系开发者!',
                                    type: 'error'
                                })
                            })
                        }
                    }).catch(xhr => {
                        this.$message({
                            message: '系统错误，请联系开发者!',
                            type: 'error'
                        })
                    })
                } catch (error) {
                    console.error(error);
                    this.$message({
                        message: '系统错误，请联系开发者!',
                        type: 'error'
                    })
                }
            }).catch(() => { });
        }
    }
})